package com.sirdc.modules.sys.web.Node;

import com.sirdc.modules.utils.StringUtils;
import net.huashitong.node.entity.NodeNewtemplet;
import net.huashitong.node.service.NodeNewtempletService;
import net.huashitong.node.filter.NodeNewtempletFilter;
import net.huashitong.oversee.filter.CoordinateFilter;
import net.huashitong.oversee.filter.SupervisionTaskFilter;
import net.huashitong.oversee.service.CoordinateService;
import net.huashitong.oversee.service.SupervisionTaskService;
import net.huashitong.user.entity.BnpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.WebUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 节点模板管理
 * Created by hyp1202 on 2018/7/4.
 */
@Controller
@RequestMapping("/NodeManage")
public class SysNodeManageController {
    @Autowired
    private NodeNewtempletService nodeNewtempletService;
    @Autowired
    private SupervisionTaskService supervisionTaskService;
    @Autowired
    private CoordinateService coordinateService;
    @ModelAttribute("headType")
    public String returnHeadType(){
        return "管理模块";
    }



    /**
     * 加载页面
     * @return
     */
    @RequestMapping(value = "/go/list" ,method = RequestMethod.GET)
    public String initPage(@ModelAttribute NodeNewtempletFilter filter, HttpServletRequest request, Model model) {

        //待办任务个数
        int nodeCount = (int) WebUtils.getSessionAttribute(request, "nodeCount");
        model.addAttribute("nodeCount", nodeCount);

        int myTaskNum = (int) WebUtils.getSessionAttribute(request, "myTaskNum");
        int quetionNum = (int) WebUtils.getSessionAttribute(request, "quetionNum");
        model.addAttribute("myTaskNum", myTaskNum);
        model.addAttribute("quetionNum", quetionNum);

        int myTackTaskNum = (int) WebUtils.getSessionAttribute(request, "myTackTaskNum");
        model.addAttribute("myTackTaskNum", myTackTaskNum);

        List<NodeNewtemplet> list = nodeNewtempletService.getNodeTempletInfo(filter);
        model.addAttribute("type",filter.getNodeType());
        model.addAttribute("list",list);
        model.addAttribute("leftType","节点模板管理");
        return "/modules/hardWork/user_jdManger";
    }

    /**
     * 查询
     * @param filter
     * @return
     */
//    @ResponseBody
//    @RequestMapping(method = RequestMethod.POST)
//    public String query(@ModelAttribute NodeNewtempletFilter filter) {
//        //String userid = SysUserUtils.getUserId();
//        List<NodeNewtemplet> list = nodeNewtempletService.getNodeTempletInfo(filter);
//        return null;
//    }

    /**
     * 删
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/delete/{id}")
    public String deleteUser(@PathVariable List<String> id) {
        nodeNewtempletService.batchDelete(id);
        return null;
    }

    /**
     * 增
     * @param nodeNewtemplet
     * @return
     */

    @ResponseBody
    @RequestMapping(value = "/create",method=RequestMethod.POST)
    public String addUser(@ModelAttribute NodeNewtemplet nodeNewtemplet){
        nodeNewtempletService.save(nodeNewtemplet);
        return null;
    }

    @RequestMapping(value = "/create")
    public String showAddUser(@ModelAttribute NodeNewtempletFilter filter){
        return null;
    }

    /**
     * 改
     * @param nodeNewtemplet
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    public String updateUser(@ModelAttribute NodeNewtemplet nodeNewtemplet){
        nodeNewtempletService.update(nodeNewtemplet);
        return null;
    }

    @RequestMapping(value = "/edit")
    public String showUpdateUser(@ModelAttribute NodeNewtempletFilter filter){
        return null;
    }

}
